package com.czy.daishusys.adapter;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.czy.daishusys.R;
import com.czy.daishusys.entity.DeliverGoodsModel;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by asus on 2017/12/4.
 */

public class DeliverGoodsItemAdapter  extends BaseQuickAdapter<DeliverGoodsModel.DataBean.UListBean.OrderItemsBean,BaseViewHolder>{
    private onGoodsCheckedListener goodsCheckedListener;
    public DeliverGoodsItemAdapter(int layoutResId, @Nullable List<DeliverGoodsModel.DataBean.UListBean.OrderItemsBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, final DeliverGoodsModel.DataBean.UListBean.OrderItemsBean item) {
        final CheckBox cbDeliverGoods = (CheckBox) holder.getView(R.id.cb_deliver_goods);
        ImageView    ivDeliverGoodsImg = (ImageView) holder.getView(R.id.iv_deliver_goods_img);
        TextView   tvDeliverGoodsName = (TextView) holder.getView(R.id.tv_deliver_goods_name);
        TextView tvDeliverGoodsSale = (TextView) holder.getView(R.id.tv_deliver_goods_sale);
        TextView tvDeliverGoodsOrigin = (TextView) holder.getView(R.id.tv_deliver_goods_origin);
        TextView tvDeliverGoodsStandard = (TextView) holder.getView(R.id.tv_deliver_goods_standard);
        TextView   tvDeliverGoodsCount = (TextView) holder.getView(R.id.tv_deliver_goods_count);
        TextView  tvDeliverWay = (TextView) holder.getView(R.id.tv_deliver_way);
        x.image().bind(ivDeliverGoodsImg, item.getLogo(), new ImageOptions.Builder()
                .setImageScaleType(ImageView.ScaleType.FIT_XY)
                .setFailureDrawableId(R.mipmap.icon_goods_list_default)
                .setLoadingDrawableId(R.mipmap.icon_goods_list_default)
                .setIgnoreGif(false)
                .build());
        tvDeliverGoodsName.setText(item.getItemName());
        tvDeliverGoodsSale.setText("¥" + String.format("%.2f", item.getPrice()));
        tvDeliverGoodsOrigin.setText("¥" + String.format("%.2f", item.getGoodsSpecValuesPrice()));
        tvDeliverGoodsOrigin.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

        if (TextUtils.isEmpty(item.getSpecValue())||"规格:无规格".equals(item.getSpecValue())){
            tvDeliverGoodsStandard.setText("");
        }
        else {
            tvDeliverGoodsStandard.setText(item.getSpecValue());
        }

        tvDeliverGoodsCount.setText("x" + item.getCount());
        tvDeliverWay.setText("配送方式:" + item.getName());
        cbDeliverGoods.setTag(item);
        /*cbDeliverGoods.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (cbDeliverGoods.getTag().equals(item)) {
                    if (goodsCheckedListener != null) {
                        goodsCheckedListener.onGoodsCheckedChange(getParentPosition(), isChecked);
                    }
                }

            }
        });*/
        cbDeliverGoods.setChecked(item.isGoodsChecked());
    }
    public interface onGoodsCheckedListener {
        void onGoodsCheckedChange(int position, boolean isChecked);
    }


    public void setOnGoodsCheckedListener(onGoodsCheckedListener goodsCheckedListener) {
        this.goodsCheckedListener = goodsCheckedListener;
    }

}
